#ifndef Astar_H
#define Astar_H
#define _SCL_SECURE_NO_WARNINGS

#include <vector>
#include "boost/multi_array.hpp"
#include <cstdlib>

#include "Position.h"
#include "objects.h"

class Astar
{
public:



	//konstruktor
	Astar(boost::multi_array<Cell, 2> *terrain, int width, int height, double blockSize); //startar hela processen med Astar
	void setTerrain(boost::multi_array<Cell, 2> *terrain, int width, int height, double blockSize);
	std::vector<PosDouble> getPath(PosDouble s, PosDouble e);

private:

	//Funktioner
	int getHeuristic(PosInt &temp);
	int getWalked(PosInt &current, PosInt &next, PosInt &previous);

	std::vector<PosDouble> findPath();
	
	void resetTerrain();
	void calcPerimeter(PosInt & current);
	bool cutCorner(int a, int b, PosInt &current);
	PosInt getNearest(PosInt start, PosInt end);
	void addItemToHeap(Cell *tempCell, PosInt &temp);
	void updateHeap(Cell *currentCell, PosInt &current);

	//Variabler
	int width, height, numberOfOpenItems, newOpenListItemID;
	double blockSize;

	int openList[64*48]; //1 dimensional array holding ID# of open list items
	int openX[64*48]; //1d array stores the x location of an item on the open list
	int openY[64*48]; //1d array stores the y location of an item on the open list
	int Fcost[64*48];	//1d array to store F cost of a cell on the open list

	std::vector<PosInt> path;
	boost::multi_array<Cell, 2> *terrain;
	PosInt startP, endP;
	PosDouble endPO, startPO; //start och slutposition i mapen.
};

#endif